from pymongo import MongoClient

client = MongoClient("localhost")
db=client['beike_house']
coll=db['beike_beike_second_hand_details']
import redis

pool = redis.ConnectionPool(host='localhost',db=7, port=6379, decode_responses=True)
r = redis.Redis(connection_pool=pool)

redis_key = 'xiaoqu'
cursor = int(r.get(redis_key)) if r.exists(redis_key) else 0
for index,value in enumerate(coll.find().skip(cursor)):
    # print(index)
    print(cursor + index     )
    r.sadd("xiaoqu_urls",value['communityurl'])
    r.set(redis_key,str(index + cursor))